﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Ajax.Common;

namespace Ajax.Web.UI
{
	public class Channel
	{
		public static string ProTxtList(int pId, int kId)
		{
			Ajax.BLL.Channel bll = new Ajax.BLL.Channel();
			StringBuilder strTxt = new StringBuilder();
			DataTable dt = bll.GetList(pId, kId);
			if (dt.Rows.Count > 0)
			{
				strTxt.Append("<dl>\n");
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					DataRow dr = dt.Rows[i];
					if (Convert.ToInt32(dr["ClassLayer"]) == 1)
					{
						if (i > 0)
						{
							strTxt.Append("</dl>\n<dl>\n");
						}
						strTxt.Append("<dt>" + dr["Title"].ToString() + "</dt>\n");
					}
					else
					{
						strTxt.Append("<dd><a href=\"Product-" + dr["Id"].ToString() + ".html\" title=\"" + dr["Title"].ToString() + "\">" + StringPlus.CutString(dr["Title"].ToString(), 22) + "</a></dd>\n");
					}
				}
				strTxt.Append("</dl>\n");
			}

			return strTxt.ToString();
		}

		public static string ViewTxtList(int pId, int kId, string txtUrl)
		{
			Ajax.BLL.Channel bll = new Ajax.BLL.Channel();
			StringBuilder strTxt = new StringBuilder();
			DataTable dt = bll.GetList(pId, kId);
			if (dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					DataRow dr = dt.Rows[i];
					if (dr["ParentId"].ToString() == "0")
					{
						strTxt.Append("<li><a href=\"" + txtUrl + "-" + dr["Id"].ToString() + ".html\" title=\"" + dr["Title"].ToString() + "\">" + StringPlus.CutString(dr["Title"].ToString(), 20) + "</a></li>\n");
					}
				}
			}

			return strTxt.ToString();
		}

		//输出栏目名称
		public static string ViewChannelTitle(int classId)
		{
			Ajax.BLL.Channel bll = new Ajax.BLL.Channel();
			if (bll.Exists(classId))
			{
				Ajax.Model.Channel model = bll.GetModel(classId);
				return model.Title;
			}
			return "所有列表";
		}
	}
}
